﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RA.Services;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Drawing;
using RA.Common;

namespace RA.UI.Model
{
    public class TemplatesManagerModel
    {
        ImageProcessService _imageProcessService;

        public TemplatesManagerModel(ImageProcessService imageProcessService)
        {
            _imageProcessService = imageProcessService;
        }

        public Templates GetTemplates(string fileName)
        {
            using (FileStream fs = new FileStream(fileName, FileMode.Open))
                return (Templates)new BinaryFormatter().Deserialize(fs);
        }

        public void SaveTemplates(Templates templates, string fileName)
        {
            using (FileStream fs = new FileStream(fileName, FileMode.Create))
                new BinaryFormatter().Serialize(fs, templates);
        }

        public Templates FindTemplates(Bitmap bitmap)
        {
            return _imageProcessService.GetTemplates(bitmap);
        }
    }
}
